Passed
Push — feature/lighthouse ( 506e99...db2e00 )
by Kevin Van
11:37 queued 05:51
created

NewsItemFeatured   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 1
1
import React, { Component } from "react"
2
3
import { Card, CardImage, CardVertical } from "./cards"
4
5
import "./news-item.scss"
6
7
/**
8
 * Render a single news item in default card layout.
9
 */
10
export class NewsItemCard extends Component {
11
  render() {
12
    const { node, teaser = false } = this.props
13
    const localFile =
14
      node.relationships.field_media_article_image.relationships
15
        .field_media_image.localFile
16
    const summary = teaser && node.body.summary
17
18
    const relatedTags = node.relationships.field_tags || []
19
20
    return (
21
      <Card
22
        title={node.title}
23
        body={summary}
24
        localFile={localFile}
25
        link={node.path.alias}
26
        metadata={true}
27
        tags={relatedTags}
28
        created={node.created}
29
        key={node.nid}
30
        className={"test"}
31
      />
32
    )
33
  }
34
}
35
36
/**
37
 * Render a single news item in image focus card layout.
38
 */
39
export class NewsItemFeatured extends Component {
40
  render() {
41
    const { node } = this.props
42
    const localFile =
43
      node.relationships.field_media_article_image.relationships
44
        .field_media_image.localFile
45
46
    return (
47
      <CardImage
48
        title={node.title}
49
        localFile={localFile}
50
        link={node.path.alias}
51
      />
52
    )
53
  }
54
}
55
56
/**
57
 * Render a single news item in vertical image card layout.
58
 */
59
export class NewsItemSquare extends Component {
60
  render() {
61
    const { node } = this.props
62
    const localFile =
63
      node.relationships.field_media_article_image.relationships
64
        .field_media_image.localFile
65
66
    return (
67
      <CardVertical
68
        title={node.title}
69
        localFile={localFile}
70
        link={node.path.alias}
71
      />
72
    )
73
  }
74
}
75
76
/**
77
 * Render news item in appropriate layout depending on the aspect ratio.
78
 */
79
export class NewsItemCardRatio extends Component {
80
  render() {
81
    const { node, teaser = false } = this.props
82
83
    const aspectRatio =
84
      node.relationships.field_media_article_image.relationships
85
        .field_media_image.localFile.childImageSharp.fluid.aspectRatio
86
87
    if (aspectRatio >= 1) {
88
      return <NewsItemCard node={node} teaser={teaser} />
89
    } else {
90
      return <NewsItemSquare node={node} />
91
    }
92
  }
93
}
94
95
/**
96
 * Render a single KCVV TV item in default card layout.
97
 */
98
export class KcvvTvCard extends Component {
99
  render() {
100
    const { node } = this.props
101
    const localFile =
102
      node.relationships.field_media_article_image.relationships
103
        .field_media_image.localFile
104
    const summary = `${node.title}<br/><br/>Bekijk hier het wedstrijdverslag, interviews, nabespreking... en stem voor je man van de match!`
105
    return (
106
      <Card
107
        title={"KCVV TV"}
108
        icon={"fa-facebook-square"}
109
        body={summary}
110
        localFile={localFile}
111
        link={node.field_website.uri}
112
        metadata={true}
113
        key={node.nid}
114
        created={node.created}
115
      />
116
    )
117
  }
118
}
119